package es.uned.dia.james.helperUI;
import java.util.regex.*;

public class Parser {	
	private static String d_regex = "([+]|-)?[0-9]+([.][0-9]+)?((e|E)([+]|-)?[0-9]+)?";
	private static String v_regex = "[\\[](\\s)*" + d_regex + "((\\s)+" + d_regex + ")*(\\s)*[\\]]";
	private static Pattern p = Pattern.compile(v_regex);
	
	public Parser() {}
	
	public static double[] parseVector(String input) {
		Matcher m = p.matcher(input);
	
		if(!m.matches()) return null;
			
		String[] item = input.substring(1, input.length()-1).split("\\s+");
		double[] result = new double[item.length];
		for(int i=0; i<item.length; i++) if(item[i].length() > 0) result[i] = Double.parseDouble(item[i]);

		return result;
	}
}
